<?php
require_once('common_view_functions.php');

function get_avatar_name($user_id, $rand) {
	$fn = $_SERVER['DOCUMENT_ROOT'] . '/img/avatars/avt_' . $user_id . '_48x48.jpg';
	if(file_exists($fn)) {
		if($rand) {
			return 'avt_' . $user_id . '_48x48.jpg?R=' . rand();
		} else {
			return 'avt_' . $user_id . '_48x48.jpg';
		}
	} else {
		return 'avt_-1_48x48.jpg';
	}
}

$login_link_text = '';

if($is_community_member === TRUE) {
	$login_link_text = '<a href="' . make_blog_url($current_user_id, $current_user_data->user_url) . '/mgmt' . ($unread_pm_num > 0 ? '/messages' : '') . '">' . lang('n8_home_nav_loginStatusYes') . $current_user_data->user_name . ($unread_pm_num > 0 ? ' ( <span class="hasNewMsg">' . $unread_pm_num . '</span> )' : '') . '</a>';
} else {
	$login_link_text = '<a href="/login">' . lang('n8_home_nav_loginStatusNo') . '</a>';
}

$show_ie_warning = $ie_warning;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title><?php echo($this->config->item('SiteTitle')); ?></title>
<link rel="shortcut icon" href="/img/favicon.ico" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="/rss" />

<link rel="stylesheet" type="text/css" href="/css/home.css" />
<link rel="stylesheet" type="text/css" href="/css/tags.css" />
<link rel="stylesheet" type="text/css" href="/css/expressions.css" />
<link rel="stylesheet" type="text/css" href="/css/emotag.css" />
</head>
<body>
	<?php if($show_ie_warning) { ?>
	<div id="ie_warning">建议使用 <a href="http://getfirefox.com/" target="_blank">Firefox</a>、<a href="http://www.google.com/chrome" target="_blank">Chrome</a> 或 Safari 浏览器访问本站，使用其他软件（比如 Internet Explorer）浏览可能无法获得最佳体验！</div>
	<?php } ?>
	<div id="header">
		<div id="nav_wrapper">
			<ul id="fp_nav">
				<li><a href="javascript:;" id="lnkToggleNewEntryList"><?php echo(lang('n8_home_nav_newEntryList')); ?></a></li>
				<li><?php echo($login_link_text); ?></li>
			</ul>
			<div class="z"></div>
		</div>
		<div id="search_wrapper">
			<form action="http://www.google.com/cse" id="frmSearch" target="_blank">
				<input type="hidden" name="cx" value="015543097987975193314:l7aecp-nprg" />
				<input type="hidden" name="ie" value="UTF-8" />
				<input type="text" id="txtSearch" name="q" class="textBox" title="<?php echo(lang('n8_home_nav_searchTitle')); ?>" title="<?php echo(lang('n8_home_nav_searchTitle')); ?>" style="width:12em;" />
				<input type="hidden" name="ie" value="UTF-8" />
			</form>
		</div>
	</div>
	
	<div id="bdy">
		<div id="body_wrapper">
			
		<div id="main">
			<div id="le">
				<?php foreach($latest_entries as $le) { ?>
				<a href="<?php echo(make_blog_url($le->blogger_id, $le->user_url) . '/entry/' . $le->id); ?>"><div class="lei exprs_<?php echo($le->expression); ?>"><h4><?php echo(htmlspec($le->title)); ?> / <span class="au"><?php echo($le->author_name); ?></span></h4></div></a>
				<?php } ?>
			</div>
			
			<div id="blgr_boxes">
				
				<?php foreach($bloggers as $bl) { ?>
				
				<div class="mbr">
					<div class="avt"><a href="<?php echo(make_blog_url($bl->id, $bl->user_url)); ?>"><img alt="" src="/img/avatars/<?php echo(get_avatar_name($bl->id, $avatar_refresh)); ?>" border="0" /></a></div>
					<div class="ath"><?php echo(htmlspec($bl->user_name)); ?></div>
					<h3><a href="<?php echo(make_blog_url($bl->id, $bl->user_url)); ?>"><?php echo(htmlspec($bl->title)); ?></a></h3>
					<div class="num"><?php echo($bl->entry_num); ?><br /><?php echo(is_null($bl->comment_num) ? '0' : $bl->comment_num); ?></div>
				</div>
				
				<?php } ?>
				<div class="z"></div>
			</div><!-- /blgr_boxes -->
		</div>
		
		<div id="side">
			<div id="etg">
				<div id="etg1" style="display:none;"></div>
				<div id="etpg">
					<a href="javascript:;" rel="prev">&laquo;</a>
					<span>Loading...</span>
					<a href="javascript:;" rel="next">&raquo;</a>
				</div>
			</div>
		</div><!-- /side -->
		
		</div><!-- /body_wrapper -->
	</div>

<!-- Scripts -->
<script type="text/javascript" src="/js/3rd/jquery.pack.js"></script>
<script type="text/javascript" src="/js/3rd/json2.js"></script>
<script type="text/javascript">
<!--
var loadEmoTagPageDone = false;
var prevPg = 0;
var nextPg = 0;

function loadEmoTags(pg) {
	$("#etg1").fadeOut(function() {
		$("#etg1").load("/home/emotags_list/" + pg, function() {
			$("#etg1").fadeIn();
			var pagingInfo = $("#hidEmoTagPaging").val();
			pagingInfo = pagingInfo.split("|");
			prevPg = pagingInfo[0];
			$("#etpg span").text(pagingInfo[1]);
			nextPg = pagingInfo[2];
			loadEmoTagPageDone = true;
		});
	});
}

function toggleMenu() {
	$("#lnkToggleNewEntryList").toggleClass("fp_nav_hover").blur();
}
function toggleMenu2() {
	$("#lnkToggleQuickEmoTag").toggleClass("fp_nav_hover").blur();
}

$(document).ready(function() {
	$("#lnkToggleNewEntryList").click(function() {
		$("#le").slideToggle("normal", toggleMenu);
	});
	
	$("#lnkToggleQuickEmoTag").click(function() {
		$("#qet").slideToggle("normal", toggleMenu2);
	});
	
	$("#etpg a").click(function() {
		if(!loadEmoTagPageDone) {
			return;
		}
		var way = $(this).attr("rel");
		$("#etpg span").text("Loading...");
		if(way == "prev") {
			loadEmoTags(prevPg);
		} else if(way == "next") {
			loadEmoTags(nextPg);
		}
	});
	
	// emoTags
	loadEmoTags(0);
	setInterval("loadEmoTags(0);", 1000 * 60 * 5);
	
	// ie-warning related
	setTimeout(function() {
		$("#ie_warning").hide();
	}, 4000);
});
// -->
</script>
<!-- /Scripts -->
	<?php require('blog/common_footer.php'); ?>
</body>
</html>